package com.zhs.smartmall.product.service.impl;


import com.zhs.smartmall.product.model.PmsAttr;
import com.zhs.smartmall.product.dao.PmsAttrDao;
import com.zhs.smartmall.product.service.IPmsAttrService;
import com.zhs.smartmall.product.dto.PmsAttrDto;


import com.zhs.smartmallcommon.exception.ServiceException;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhs.smartmallcommon.Enum.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import cn.hutool.core.bean.BeanUtil;
import javax.annotation.Resource;
import org.springframework.transaction.annotation.Transactional;


/**
 *
 * @author zhenghuisheng
 * @since 2023-11-11
 */
@Service
@Slf4j
public class PmsAttrServiceImpl extends ServiceImpl< PmsAttrDao, PmsAttr> implements IPmsAttrService {

    @Resource
    private PmsAttrDao pmsAttrDao;

    @Override
    @Transactional
    public R addOrUpdate(PmsAttrDto pmsAttrDto) {
        if (BeanUtil.isEmpty(pmsAttrDto)) throw new ServiceException("数据不能为空");
        PmsAttr pmsAttr = new PmsAttr();
        BeanUtil.copyProperties(pmsAttrDto,pmsAttr);
        if (pmsAttrDto.getId() == null){
            pmsAttrDao.insert(pmsAttr);
            return R.ok("数据插入成功");
        }else {
            pmsAttrDao.updateById(pmsAttr);
            return R.ok("数据更新成功");
        }
    }
}